package com.meishij.adapter;

import android.content.Context;
import android.content.Intent;
import android.icu.util.IslamicCalendar;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.meishij.MallZcActivity;
import com.meishij.R;
import com.meishij.entry.MallEntry;

import java.util.List;

/**
 * Created by 肖荣 on 2016/10/13.
 */

public class MallZcAdapter extends RecyclerView.Adapter<MallZcAdapter.ViewHolder> {
    private Context context;
    private List<MallEntry.ZcBean> list;

    public MallZcAdapter(Context context, List<MallEntry.ZcBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.layout_mall_zc_item, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        holder.mall_zc_item_image.setImageURI(list.get(position).getImage());
        holder.mall_zc_item_image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String url = list.get(position).getUrl();//这个url是跳转的界面上的webView需要的
                Intent intent=new Intent(context, MallZcActivity.class);
                intent.putExtra("url",url);
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        private SimpleDraweeView mall_zc_item_image;

        public ViewHolder(View itemView) {
            super(itemView);
            mall_zc_item_image = ((SimpleDraweeView) itemView.findViewById(R.id.mall_zc_item_image));
        }
    }
}
